package com.example.knowman.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.knowman.ObService.*;
import com.example.knowman.ReturnMessage.Message;
import com.example.knowman.ReturnMessage.MessageBackKnowMainId;
import com.example.knowman.dao.knowLabelDetailAddLabels;
import com.example.knowman.dao.knowMainEx;
import com.example.knowman.dao.knowMainEx9_5ByPeriod;
import com.example.knowman.dao.knowMainExDaBiao;
import com.example.knowman.entity.*;
import com.example.knowman.mapper.KnowCategoryMapper;
import com.example.knowman.mapper.KnowMainMapper;
import com.example.knowman.mapper.Log4operateMapper;
import com.example.knowman.mapper.StaffListMapper;
import com.example.knowman.service.IKnowCategoryService;
import com.example.knowman.service.IKnowMainService;
import com.example.knowman.service.ILog4operateService;
import com.example.knowman.service.IStaffListService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class Log4operateServiceImpl extends ServiceImpl<Log4operateMapper, log4operate> implements ILog4operateService {


    @Override
    public IPage<log4operate> getAll(Integer pageNum, Integer pageSize, String operator, String createtime, Integer timeType) {
        IPage<log4operate> Respage = new Page<>(pageNum, pageSize);

        if(timeType == 1){
            Respage = this.lambdaQuery()
                    .eq(operator!=null && !operator.isEmpty(),log4operate::getOperator,operator)
                    .apply("YEAR(\"createtime\") = {0}", createtime)
                    .page(Respage);
        }
        else if (timeType == 2){
            Respage = this.lambdaQuery()
                    .eq(operator!=null && !operator.isEmpty(),log4operate::getOperator,operator)
                    .apply("DATE_FORMAT(\"createtime\", '%Y-%m') = {0}", createtime)
                    .page(Respage);
        }
        else if (timeType == 3){

            Respage = this.lambdaQuery()
                    .eq(operator!=null && !operator.isEmpty(),log4operate::getOperator,operator)
                    .apply("DATE_FORMAT(\"createtime\", '%Y-%m-%d') = {0}", createtime)
                    .page(Respage);
        }
        else {

            Respage = this.lambdaQuery()
                    .eq(operator!=null && !operator.isEmpty(),log4operate::getOperator,operator)
                    .page(Respage);
        }

        return Respage;
    }

    @Override
    public boolean insertSingle(String operator, String content, String ipAddress) {
        boolean flag = true;



        log4operate temp = new log4operate();
        temp.setOperator(operator);
        temp.setContent(content);
        temp.setIpAddress(ipAddress);
//        temp.setRecId(null);

//        this.save(temp);
        try{
            this.save(temp);
        }catch (Exception e){
            flag = false;
        }


        return flag;
    }
}
